/**
 * 
 */
package com.cipe.cmrs.service;

import java.util.Date;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.cipe.cmrs.dao.BaseRefDao;

/**
 * @author Krishna
 * 
 */
@Service
public class CipeScheduler {

	@Autowired
	BaseRefDao refDao;

	/**
	 * This procedure update the dashboard link table in every 30 mins 
	 * this is no more required as the design change now.
	 * All function related to dash board we can delete.
	 */
	/*@Scheduled(cron = "0 0/40 * * * ?")
	@PostConstruct
	public void callDashBiardCountProcedure() {
		refDao.callStroredProcedure("EXECUTE  getDashboard_count ");

	}
*/
	/**
	 * This method call in exactly midnight everyday. Before it was calling in every minute
	 */
	@Scheduled(cron = "0 0/1 * * * ?")
	//@Scheduled(cron="0 1 0 * * ?")
	public void callAllProcedureRelatedToOneDay() {
		refDao.callStroredProcedure("EXECUTE AllProcedureRelatedToOneDay ");
	}

	@Scheduled(cron="0 1 0 * * ?")
	public void midNightCall(){
		refDao.callStroredProcedure("Update project set statusoverride=0 , budgetoverride=0");
		//logger.debug("Modnight call at "+ new Date());
	}
	/**
	 * This method call in exactly midnight everyday. Before it was calling in every minute
	 */
	@PostConstruct
	@Scheduled(cron = "0 0/1 * * * ?")
	//@Scheduled(cron="0 1 0 * * ?")
	public void callUpdateActionalableMessage() {
		synchronized (CipeScheduler.class) {
		//logger.debug("Job started at" +new Date()+" By the thread  "+Thread.currentThread().getName());
		refDao.callStroredProcedure("EXECUTE updateActionalableMessage ");
		//logger.debug("Job Ended at" +new Date()+" By the thread  "+Thread.currentThread().getName());
		}
	}

}
